#include <func.h>
#define N 10
typedef struct{
    pthread_mutex_t mutex;
    int add;
}set;
void *thfunc(void *p)
{
    printf("I am subthread!\n");
    int i;
    set *et=(set*)p;
    printf("subadd=%d\n",et->add);
    for(i=0;i<N;++i)
    {
    printf("subadd=%d\n",et->add);
        pthread_mutex_lock((pthread_mutex_t*)p);
        et->add++;
        pthread_mutex_unlock((pthread_mutex_t*)p);
    }
}
int main(int argc,char *argv[])
{
    int ret;
    int i;
    pthread_t pthid;
    set et;
    et.add=0;
    printf("main add=%d\n",et.add);
    ret=pthread_create(&pthid,NULL,thfunc,(void*)&et);
    THREAD_ERROR_CHECK(ret,"pthread_create");
    printf("I am main thread\n");
    ret=pthread_mutex_init(&et.mutex,NULL);
    for(i=0;i<N;++i)
    {
    printf("main add=%d\n",et.add);
        pthread_mutex_lock(&et.mutex);
        et.add++;
        pthread_mutex_unlock(&et.mutex);
    }
    pthread_join(pthid,NULL);
    printf("main add=%d\n",et.add);
    THREAD_ERROR_CHECK(ret,"pthread_join");
    return 0;
}

